babl-cache: factor out construction of header line
authorØyvind Kolås <pippin@gimp.org>
Tue, 29 Nov 2016 21:45:56 +0000 (22:45 +0100)
committerØyvind Kolås <pippin@gimp.org>
Tue, 29 Nov 2016 21:45:56 +0000 (22:45 +0100)
babl/babl-cache.c

index 1f0b6f5f68ca31321417a776921c04f79a085d64..818c12663a3ed477a57874585ea16c5cbead21e4 100644 (file)
@@ -135,6 +135,14 @@ static int compare_fish_pixels (const void *a, const void *b)
          ((*fb)->fish.processings - (*fa)->fish.processings);
 }
 
+static const char *cache_header (void)
+{
+  static char buf[2048];
+  sprintf (buf, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f",
+  BABL_GIT_VERSION, _babl_max_path_len (), _babl_legal_error ());
+  return buf;
+}
+
 void babl_store_db (void)
 {
   BablDb *db = babl_fish_db ();
@@ -142,8 +150,7 @@ void babl_store_db (void)
   FILE *dbfile = fopen (fish_cache_path (), "w");
   if (!dbfile)
     return;
-  fprintf (dbfile, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f\n",
-           BABL_GIT_VERSION, _babl_max_path_len (), _babl_legal_error ());
+  fprintf (dbfile, "%s\n", cache_header ());
 
   /* sort the list of fishes by usage, making next run more efficient -
    * and the data easier to approach as data for targeted optimization
@@ -254,10 +261,7 @@ void babl_init_db (void)
         case '#':
           /* if babl has changed in git .. drop whole cache */
           {
-            char buf[2048];
-            sprintf (buf, "#%s BABL_PATH_LENGTH=%d BABL_TOLERANCE=%f",
-               BABL_GIT_VERSION, _babl_max_path_len (), _babl_legal_error ());
-            if (strcmp ( token, buf))
+            if (strcmp ( token, cache_header ()))
             {
               free (contents);
               return;